<template>
	<view style="background-color: #f3f4f5;">
		<u-navbar :is-back="true" title="添加工作安排" title-color="white" :border-bottom="false" :background="background">
			<view class="navbar-right" slot="right">
				<u-icon name="order" color="#ffffff" slot: size="30"
					@click="openinfo('/pages/order/makeTable/addArrange/myArrange/myArrange')"
					style="margin-right: 20rpx;"></u-icon>
			</view>
		</u-navbar>



		<view class="u-p-15 u-font-12" style="background-color: #f3f4f5;color: #b2b2b2;">
			添加工作安排后，该周期内无法接受患者预约/咨询。
		</view>
		<view class="" style="padding: 0rpx 26rpx;background-color: #FFFFFF;">

			<u-cell-group class="u-m-b-26" style="margin-bottom: 20rpx;background-color: #FFFFFF;">
				<u-cell-item title="开始时间" @click="pickerShowTimebegin()" :value="beginTime">
				</u-cell-item>
				<!-- 弹出picker开始时间 -->
				<u-picker v-model="showTimebegin" title="选择日期" mode="time" @confirm="timeBeginChange" :params="params">
				</u-picker>
				<u-cell-item title="结束时间" @click="pickerShowTimeend()" :value="endTime">
				</u-cell-item>
				<!-- 弹出picker结束时间 -->
				<u-picker v-model="showTimeend" title="选择日期" mode="time" @confirm="timeEndChange" :params="params">
				</u-picker>
			</u-cell-group>

			<u-cell-group class="u-m-b-26 " style="margin-bottom: 20rpx;background-color: #FFFFFF;">
				<u-cell-item title="已有其他工作安排" :arrow="false">
					<u-radio-group v-model="value" @change="radioGroupChange">
						<u-radio @change="radioChange" v-for="(item, index) in list1" :key="index" :name="item.name"
							:disabled="item.disabled">
						</u-radio>
					</u-radio-group>
				</u-cell-item>

				<u-cell-item title="个人调休" :arrow="false">
					<u-radio-group v-model="value" @change="radioGroupChange">
						<u-radio @change="radioChange" v-for="(item, index) in list2" :key="index" :name="item.name"
							:disabled="item.disabled">
						</u-radio>
					</u-radio-group>
				</u-cell-item>
				<u-cell-item title="其他原因" :arrow="false">
					<u-radio-group v-model="value" @change="radioGroupChange">
						<u-radio @change="radioChange" v-for="(item, index) in list3" :key="index" :name="item.name"
							:disabled="item.disabled">
						</u-radio>
					</u-radio-group>
				</u-cell-item>
			</u-cell-group>

		</view>
		<u-button type="primary" style="width: 90%;position: fixed;bottom: 60rpx;left: 5%;" @click="endClick()">确认修改
		</u-button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import buttonContent from '@/components/custom/buttonContent.vue'
	export default {
		components: {
			buttonContent
		},
		data() {
			return {
				background: {
					backgroundColor: '#00a8ff'
				},
				showTimebegin: false,
				showTimeend: false,
				beginTime: '', // 开始时间
				endTime: '', // 结束时间
				params: {
					year: false,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				list1: [{
					name: '已有其他安排',
					disabled: false
				}],
				list2: [{
					name: '个人调休',
					disabled: false
				}],
				list3: [{
					name: '其他原因',
					disabled: false
				}],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: 'orange',
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中

				startTimestamp: '', // 开始时间戳
				endTimestamp: '', // 结束时间戳
				msg: ''
			}
		},
		methods: {
			pickerShowTimebegin() {
				this.showTimebegin = true;
			},
			pickerShowTimeend() {
				this.showTimeend = true;
			},

			// 开始时间 结束时间pick回调函数

			timeBeginChange(e) {
				this.beginTime = e.month + "月" + e.day + "日 " + e.hour + ":" + e.minute;

				let dt = "";
				let year = new Date().getFullYear();
				dt = year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute;
				var timestamp1 = (new Date(dt)).getTime() / 1000
				console.log("时间戳:", timestamp1);
				console.log("日期:", dt);
				this.startTimestamp = timestamp1; // 开始时间戳
			},
			timeEndChange(e) {
				this.endTime = e.month + "月" + e.day + "日 " + e.hour + ":" + e.minute;
				let dt = "";
				let year = new Date().getFullYear();
				dt = year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute;
				var timestamp1 = (new Date(dt)).getTime() / 1000
				console.log("时间戳:", timestamp1);
				console.log("日期:", dt);
				this.endTimestamp = timestamp1; // 结束时间戳
			},
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
				this.msg = e;
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				// console.log(e);
			},
			endClick() {
				// 工作安排添加
				console.log("确认添加,请求");
				this.$apiVipCentre.setroster({
					starttime: this.startTimestamp,
					endtime: this.endTimestamp,
					msg: this.msg,
					type: ""
				}).then((res) => {
					console.log("res.data.data: ", res.data.data);
					this.$refs.uToast.show({
						title: res.data.msg
					})
					
					// 延迟3秒返回上一页
					setTimeout(()=>{
						uni.navigateBack();
					},3000)
					
					
				}).catch((err) => {
					console.log('request fail', err);
				})
			},
			openinfo(url) {
				uni.navigateTo({
					url: url,
				});
			}
		}
	}
</script>

<style>

</style>
